package com.ruicar.afs.cloud.account.common.controller;

import com.ruicar.afs.cloud.account.common.service.VoucherEntryService;
import com.ruicar.afs.cloud.account.vo.VoucherEntryVo;
import com.ruicar.afs.cloud.common.core.log.annotation.SysLog;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/6/18 14:46
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/voucherEntry")
@Api(value = "voucherEntry", description = "凭证分录信息")
public class VoucherEntryController {
    private final  VoucherEntryService voucherEntryService;

    @PostMapping("/save")
    @ApiOperation(value = "保存凭证分录信息")
    public IResponse save(@RequestBody @Validated VoucherEntryVo voucherEntryVo){
        return IResponse.success(voucherEntryService.checkAndSave(voucherEntryVo));
    }
    @PostMapping("/edit")
    @ApiOperation(value = "修改凭证分录信息")
    public IResponse edit(@RequestBody @Validated VoucherEntryVo voucherEntryVo){
        return IResponse.success(voucherEntryService.checkAndUpdate(voucherEntryVo));
    }
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "删除凭证分录信息")
    @SysLog(value = "通过id删除凭证分录信息")
    public IResponse<Boolean> delete(@PathVariable String id){
        return IResponse.success(voucherEntryService.deleteById(Long.parseLong(id)));
    }
    @PostMapping("/getAllVoucherEntry/{id}")
    @ApiOperation(value = "获取凭证分录信息")
    public IResponse getAllVoucherEntry(@PathVariable String id){
        return IResponse.success(voucherEntryService.list(Long.parseLong(id)));
    }
}
